home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------
-
- AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
- Mail Service Access Module
-
- written by Steve Falkenburg-- MacDTS
- ©1991-1993 Apple Computer, Inc.
-
- --------------
- change history
- --------------
-
- SJF 02/19/93 update for beta build b1
- SJF 10/29/92 update to a11 a11
- SJF 06/08/92 update to a8 a8
- SJF 02/15/92 first working version a4.5
- SJF 10/16/91 initial coding a3
-
- ---------------------------------------------------------------------*/
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #include <ctype.h>
- #include <string.h>
-
- #ifdef applec
- #include <strings.h>
- #endif
-
- #include "const.h"
- #include "gwerrors.h"
- #include "utils.h"
-
- #include "parser.h"
-
- short CountLines(char *text)
- {
- short numLines;
-
- for (numLines=0; *text!=0; text++)
- if (*text==CR && *(text+1)==LF)
- numLines++;
-
- return numLines;
- }
-
-
- short CountCRLines(char *text)
- {
- short numLines;
-
- for (numLines=0; *text!=0; text++)
- if (*text==CR)
- numLines++;
-
- return numLines;
- }
-
-
- void GetWord(char **word,char **text)
- {
- /* advance past white space */
-
- while (isspace(**text) || **text==',')
- (*text)++;
-
- *word = *text;
-
- /* advance pointer past word */
-
- while (**text && !isspace(**text) && **text!=',')
- (*text)++;
-
- /* advance past white space */
-
- while (isspace(**text) || **text==',')
- (*text)++;
- }
-
-
- void GetField(char **word,char **text,char delimiter,short *dataLength) // gets item from delimited list
- {
- *dataLength = 0;
-
- /* advance past white space */
-
- while (**text==delimiter)
- (*text)++;
-
- *word = *text;
-
- /* advance pointer past word */
-
- while (**text && **text!=delimiter) {
- (*text)++;
- (*dataLength)++;
- }
-
- /* advance past white space */
-
- while (**text==delimiter)
- (*text)++;
-
- while (isspace(**text) || **text==CR || **text==LF)
- (*text)++;
- }
-
-
- void GetLine(char **line,char **text)
- {
- *line = *text;
-
- while (**text && **text!=CR && **text!=LF)
- (*text)++;
-
- while (**text==CR || **text==LF)
- (*text)++;
- }
-
-
- void GetNumber(long *number,char **text)
- {
- Str255 numStr;
- char *theWord,*entryPtr;
-
- GetWord(&theWord,text);
-
- entryPtr = (char *)numStr;
- while (*theWord && *theWord!=CR && *theWord!=LF && !isspace(*theWord))
- *entryPtr++ = *theWord++;
- *entryPtr++ = '\0';
- c2pstr((char *)numStr);
-
- StringToNum(numStr,number);
- }
-
-
- void CopyWord(char *dest,char *sourceStream)
- {
- while (*sourceStream && !isspace(*sourceStream) && *sourceStream!=',')
- *dest++ = *sourceStream++;
- *dest++ = '\0';
- }
-
-
- void CopyLine(char *dest,char *sourceStream)
- {
- while (*sourceStream && *sourceStream!=CR && *sourceStream!=LF)
- *dest++ = *sourceStream++;
- *dest++ = '\0';
- }
-
-
- /* copies a line upto the next line starting with a non-white space in the first column */
-
- void CopyAndUnfoldLine(char *dest,char *sourceStream)
- {
- do {
- while (*sourceStream && *sourceStream!=CR && *sourceStream!=LF)
- *dest++ = *sourceStream++;
- if (*sourceStream==CR) {
- *sourceStream++;
- if (*sourceStream==LF)
- *sourceStream++;
- }
- } while (*sourceStream && isspace(*sourceStream));
-
- *dest++ = '\0';
- }
-
-
- void StripLF(char *data,unsigned long *length)
- {
- register char *source,*dest;
-
- if (*length > 0) {
- source = dest = data;
- while ((source - data) < (*length-1)) {
- if (*source == LF && (source==data || *(source-1)==CR))
- source++;
- else if (*source==LF) {
- *dest++ = CR;
- source++;
- }
- else
- *dest++ = *source++;
- }
- if (*source != LF && (source - data) < *length)
- *dest++ = *source++;
- *length = dest - data;
- data[*length] = '\0';
- }
- }
-
-
- OSErr AddLF(char *preLF,char **postLF)
- {
- register char *old,*new;
- short numLines;
- unsigned long newLength,oldLength;
-
- oldLength = strlen(preLF);
- numLines = CountCRLines(preLF);
- newLength = oldLength + numLines + 256; // leave some extra room for error and slop
-
- *postLF = NewPtrChk(newLength);
- if (MemError()!=noErr)
- return MemError();
-
- new = *postLF;
- old = preLF;
-
- if (*old==LF)
- old++;
-
- while ((old-preLF) < oldLength) {
- *new++ = *old++;
- if ( *(old-1)==CR && *old!=LF )
- *new++ = LF;
- }
-
- *new++ = '\0'; // null terminate new string
-
- return noErr;
- }
-